/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManageField_Skill.java
 *
 * Created on Apr 21, 2012, 7:01:20 PM
 */
package schedulerManagerment.SkillFieldManager;

import Application.MarvellFrame;
import schedulerManagerment.SkillFieldManager.jdbc.SkillList;
import schedulerManagerment.SkillFieldManager.jdbc.FieldList;
import schedulerManagerment.SkillFieldManager.entities.Skill_info;
import schedulerManagerment.SkillFieldManager.entities.Field_info;
import DataServices.Validate;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
 *
 * @author tuanIT
 */
public class ManageField_Skill extends javax.swing.JFrame implements MarvellFrame{

    private DefaultTableModel model;
    private DefaultTableModel model1;
    private FieldList flist;
    private SkillList slist;
    private int rowSelect;
    private int rowSelect1;

    /** Creates new form ManageField_Skill */
   private void setFieldTable()
   {
       model = (DefaultTableModel)FieldTable.getModel();
       model.getDataVector().clear();
       this.flist = new FieldList();
       for(Field_info f : flist.getFlist())
       {
            Object[] data = {f.getfID(),f.getfName()};
            model.addRow(data);
       }
   }
   
   private void setSkillTable()
   {
       model1 = (DefaultTableModel)SkillTable.getModel();
       model1.getDataVector().clear();
       this.slist = new SkillList();
       for(Skill_info s : slist.getsList())
       {
           Object[] data = {s.getsID(),s.getsName()};
           model1.addRow(data);
       }
   }
    
    public ManageField_Skill() {
        initComponents();
        setFieldTable();
        setSkillTable();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addFrame = new javax.swing.JFrame();
        jLabel3 = new javax.swing.JLabel();
        btnAdd1 = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        txtFName = new javax.swing.JTextField();
        addFrame2 = new javax.swing.JFrame();
        jLabel4 = new javax.swing.JLabel();
        txtSName = new javax.swing.JTextField();
        btnAdd2 = new javax.swing.JButton();
        btnCancel2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        FieldTable = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        SkillTable = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtField = new javax.swing.JTextField();
        btnSaveField = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        btnSaveSkill = new javax.swing.JButton();
        txtskill = new javax.swing.JTextField();
        btnAddfield = new javax.swing.JButton();
        btnEditfield = new javax.swing.JButton();
        btnRe1 = new javax.swing.JButton();
        btnDelField = new javax.swing.JButton();
        btnRe2 = new javax.swing.JButton();
        btnAddSkill = new javax.swing.JButton();
        btnDelSkill = new javax.swing.JButton();
        btnEditSkill = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jLabel3.setText("Field_Name :");

        btnAdd1.setText("Add");
        btnAdd1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdd1ActionPerformed(evt);
            }
        });

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout addFrameLayout = new javax.swing.GroupLayout(addFrame.getContentPane());
        addFrame.getContentPane().setLayout(addFrameLayout);
        addFrameLayout.setHorizontalGroup(
            addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addFrameLayout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnAdd1)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtFName)
                    .addComponent(btnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(50, 50, 50))
        );
        addFrameLayout.setVerticalGroup(
            addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addFrameLayout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtFName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(addFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd1)
                    .addComponent(btnCancel))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jLabel4.setText("Skill_Name :");

        btnAdd2.setText("Add");
        btnAdd2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAdd2ActionPerformed(evt);
            }
        });

        btnCancel2.setText("Cancel");
        btnCancel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancel2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout addFrame2Layout = new javax.swing.GroupLayout(addFrame2.getContentPane());
        addFrame2.getContentPane().setLayout(addFrame2Layout);
        addFrame2Layout.setHorizontalGroup(
            addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addFrame2Layout.createSequentialGroup()
                .addGroup(addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(addFrame2Layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addComponent(jLabel4))
                    .addGroup(addFrame2Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(btnAdd2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnCancel2)
                    .addComponent(txtSName, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        addFrame2Layout.setVerticalGroup(
            addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(addFrame2Layout.createSequentialGroup()
                .addGap(32, 32, 32)
                .addGroup(addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtSName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(addFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAdd2)
                    .addComponent(btnCancel2))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

        jScrollPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane1MouseClicked(evt);
            }
        });

        FieldTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Field_ID", "Field_Name "
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        FieldTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                FieldTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(FieldTable);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setText("Field Manager");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(180, 180, 180)
                        .addComponent(jLabel5)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jScrollPane2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jScrollPane2MouseClicked(evt);
            }
        });

        SkillTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Skill_ID", "Skill_Name"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        SkillTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SkillTableMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(SkillTable);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel6.setText("Skill Manager");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(170, 170, 170)
                        .addComponent(jLabel6)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setText("Field_Name:");

        txtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFieldActionPerformed(evt);
            }
        });

        btnSaveField.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Check.png"))); // NOI18N
        btnSaveField.setText("Save");
        btnSaveField.setEnabled(false);
        btnSaveField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveFieldActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(34, 34, 34)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnSaveField)
                    .addComponent(txtField, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(19, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSaveField)
                .addGap(7, 7, 7))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel2.setText("Skill_Name :");

        btnSaveSkill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Check.png"))); // NOI18N
        btnSaveSkill.setText("Save");
        btnSaveSkill.setEnabled(false);
        btnSaveSkill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveSkillActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnSaveSkill)
                        .addGap(26, 26, 26))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(txtskill)
                        .addContainerGap())))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap(20, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(txtskill, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(btnSaveSkill))
        );

        btnAddfield.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Add.png"))); // NOI18N
        btnAddfield.setText("Add");
        btnAddfield.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddfieldActionPerformed(evt);
            }
        });

        btnEditfield.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/pencil.png"))); // NOI18N
        btnEditfield.setText("Edit");
        btnEditfield.setEnabled(false);
        btnEditfield.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditfieldActionPerformed(evt);
            }
        });

        btnRe1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Load.png"))); // NOI18N
        btnRe1.setText("Refresh");
        btnRe1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRe1ActionPerformed(evt);
            }
        });

        btnDelField.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Minus Red Button.png"))); // NOI18N
        btnDelField.setText("Delete");
        btnDelField.setEnabled(false);
        btnDelField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelFieldActionPerformed(evt);
            }
        });

        btnRe2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Load.png"))); // NOI18N
        btnRe2.setText("Refresh");
        btnRe2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRe2ActionPerformed(evt);
            }
        });

        btnAddSkill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Button White Add.png"))); // NOI18N
        btnAddSkill.setText("Add");
        btnAddSkill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddSkillActionPerformed(evt);
            }
        });

        btnDelSkill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Minus Red Button.png"))); // NOI18N
        btnDelSkill.setText("Delete");
        btnDelSkill.setEnabled(false);
        btnDelSkill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDelSkillActionPerformed(evt);
            }
        });

        btnEditSkill.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/pencil.png"))); // NOI18N
        btnEditSkill.setText("Edit");
        btnEditSkill.setEnabled(false);
        btnEditSkill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditSkillActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/Import Document.png"))); // NOI18N
        jButton1.setText("back");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(btnAddfield)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelField)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnEditfield)
                        .addGap(152, 152, 152))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(20, 20, 20)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jButton1)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(btnAddSkill)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(btnDelSkill)
                                            .addGap(14, 14, 14)
                                            .addComponent(btnEditSkill)))))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRe2)
                    .addComponent(btnRe1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddfield, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnDelField, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEditfield, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRe1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(47, 47, 47)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAddSkill)
                    .addComponent(btnDelSkill, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnEditSkill, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnRe2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAddfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddfieldActionPerformed
        // TODO add your handling code here:
        addFrame.pack();
        addFrame.setVisible(true);
    }//GEN-LAST:event_btnAddfieldActionPerformed

    private void jScrollPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jScrollPane1MouseClicked

    private void FieldTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_FieldTableMouseClicked
        // TODO add your handling code here:
        rowSelect=FieldTable.getSelectedRow();
        if(rowSelect!=-1){
            showInfo();
        }
    }//GEN-LAST:event_FieldTableMouseClicked

    private void btnAdd1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdd1ActionPerformed
        // TODO add your handling code here:
        Validate v = new Validate();
        String fname = txtFName.getText();
        if(v.isEmpty(fname)== false)
        {  
        flist.insert(fname);
        setEnable(false);
        flist.refresh();
        setFieldTable();
        addFrame.setVisible(false);
        }
        else{
            JOptionPane.showMessageDialog(rootPane,"Must field!");
        }
        
    }//GEN-LAST:event_btnAdd1ActionPerformed

    private void btnRe1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRe1ActionPerformed
        // TODO add your handling code here:
        flist.refresh();
        setFieldTable();
    }//GEN-LAST:event_btnRe1ActionPerformed

    private void btnRe2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRe2ActionPerformed
        // TODO add your handling code here:
        slist.refresh();
        setSkillTable();
    }//GEN-LAST:event_btnRe2ActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        addFrame.setVisible(false);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnEditfieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditfieldActionPerformed
        // TODO add your handling code here:
        setEnable(true);
    }//GEN-LAST:event_btnEditfieldActionPerformed

    private void btnSaveFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveFieldActionPerformed
        // TODO add your handling code here:
        int id = Integer.parseInt(model.getValueAt(rowSelect, 0).toString());
        String s = txtField.getText();
        Validate v = new Validate();
        if(v.isEmpty(s)== false){
        flist.update(id,s);
        setEnable(false);
        flist.refresh();
        setFieldTable();
        }
        else {
             JOptionPane.showMessageDialog(rootPane, "Must field!");
        }
    }//GEN-LAST:event_btnSaveFieldActionPerformed

    private void btnAdd2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAdd2ActionPerformed
        // TODO add your handling code here:
        Validate v = new Validate();
        String sname = txtSName.getText();
        if(v.isEmpty(sname)== false){
        slist.insert(sname);
        setEnable1(false);
        slist.refresh();
        setSkillTable();
        addFrame2.setVisible(false);
        }
        else {
            JOptionPane.showMessageDialog(rootPane,"Must field!");
        }
    }//GEN-LAST:event_btnAdd2ActionPerformed

    private void txtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtFieldActionPerformed

    private void SkillTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SkillTableMouseClicked
        // TODO add your handling code here:
        rowSelect1=SkillTable.getSelectedRow();
        if(rowSelect1!=-1){
            showInfo1();
        }
    }//GEN-LAST:event_SkillTableMouseClicked

    private void btnAddSkillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddSkillActionPerformed
        // TODO add your handling code here:
        addFrame2.pack();
        addFrame2.setVisible(true);
    }//GEN-LAST:event_btnAddSkillActionPerformed

    private void btnEditSkillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditSkillActionPerformed
        // TODO add your handling code here:
        setEnable1(true);
    }//GEN-LAST:event_btnEditSkillActionPerformed

    private void btnSaveSkillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveSkillActionPerformed
        // TODO add your handling code here:
        int id = Integer.parseInt(model1.getValueAt(rowSelect, 0).toString());
        String s = txtskill.getText();
        Validate v = new Validate();
        if(v.isEmpty(s)==false){
        slist.update(id,s);
        setEnable1(false);
        slist.refresh();
        setSkillTable();
        } else {
        JOptionPane.showMessageDialog(rootPane, "Must field!");
        }
    }//GEN-LAST:event_btnSaveSkillActionPerformed

    private void btnCancel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancel2ActionPerformed
        // TODO add your handling code here:
        addFrame2.setVisible(false);
    }//GEN-LAST:event_btnCancel2ActionPerformed

    private void jScrollPane2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jScrollPane2MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jScrollPane2MouseClicked

    private void btnDelFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelFieldActionPerformed
        // TODO add your handling code here:
        int id = Integer.parseInt(model.getValueAt(rowSelect, 0).toString());
        flist.delete(id);
        btnEditfield.setEnabled(false);
        setEnable(false);
        flist.refresh();
        setFieldTable();
    }//GEN-LAST:event_btnDelFieldActionPerformed

    private void btnDelSkillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelSkillActionPerformed
        // TODO add your handling code here:
        int id = Integer.parseInt(model1.getValueAt(rowSelect1, 0).toString());
        slist.delete(id);
        btnEditSkill.setEnabled(false);
        setEnable1(false);
        slist.refresh();
        setSkillTable();
    }//GEN-LAST:event_btnDelSkillActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.exitFrame();
    }//GEN-LAST:event_jButton1ActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable FieldTable;
    private javax.swing.JTable SkillTable;
    private javax.swing.JFrame addFrame;
    private javax.swing.JFrame addFrame2;
    private javax.swing.JButton btnAdd1;
    private javax.swing.JButton btnAdd2;
    private javax.swing.JButton btnAddSkill;
    private javax.swing.JButton btnAddfield;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCancel2;
    private javax.swing.JButton btnDelField;
    private javax.swing.JButton btnDelSkill;
    private javax.swing.JButton btnEditSkill;
    private javax.swing.JButton btnEditfield;
    private javax.swing.JButton btnRe1;
    private javax.swing.JButton btnRe2;
    private javax.swing.JButton btnSaveField;
    private javax.swing.JButton btnSaveSkill;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField txtFName;
    private javax.swing.JTextField txtField;
    private javax.swing.JTextField txtSName;
    private javax.swing.JTextField txtskill;
    // End of variables declaration//GEN-END:variables

    private void setEnable(boolean t){
        txtField.setEditable(t);
        btnAddfield.setEnabled(!t);
        btnRe1.setEnabled(!t);
        btnSaveField.setEnabled(t);
        FieldTable.setEnabled(!t);
    }
    
    private void setEnable1(boolean t){
        txtskill.setEditable(t);
        btnAddSkill.setEnabled(!t);
        btnRe2.setEnabled(!t);
        btnSaveSkill.setEnabled(t);
        SkillTable.setEnabled(!t);
    }
    
     private void showInfo() {
        btnEditfield.setEnabled(true);
        btnDelField.setEnabled(true);
        Field_info f = flist.getById(Integer.parseInt(model.getValueAt(rowSelect, 0).toString()));
        txtField.setText(f.getfName());
        
    }
     
     private void showInfo1() {
        btnEditSkill.setEnabled(true);
        btnDelSkill.setEnabled(true);
        Skill_info s = slist.getById(Integer.parseInt(model1.getValueAt(rowSelect1, 0).toString()));
        txtskill.setText(s.getsName());
        
    }
     
     @Override
    public void startFrame(JFrame app) {
        this.root = app;
        this.setVisible(true);
        root.setEnabled(false);
    }

    @Override
    public void exitFrame() {
        root.setEnabled(true);
        this.setVisible(false);
    }
    private JFrame root;
}
